 <template>
  <div class="wrap">
    <div class="show-title">
      <span>流媒体分配设备列表</span>
    </div>
    <!-- 搜索 -->
    <div class="search-box">
      <el-input v-model="input" class="input-with-select">
        <el-select
          style="width: 150px;"
          v-model="select"
          slot="prepend"
          placeholder="请选择"
        >
          <el-option label="别称" value="1"></el-option>
          <el-option label="国标编码" value="2"></el-option>
          <el-option label="序列号" value="3"></el-option>
        </el-select>
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="fnSearch"
        ></el-button>
        <i
          slot="suffix"
          class="el-input__icon el-icon-circle-close"
          @click="FnAll()"
        ></i>
      </el-input>
    </div>
    <!-- 列表 -->
    <el-table
      ref="table"
      :data="tableData"
      border
      style="width: 100%"
      stripe
      @selection-change="handleSelectionChange"
      @sort-change="changeSort"
      :row-key="getRowKeys"
      :cell-style="changeCellStyle"
    >
      <el-table-column
        type="selection"
        width="40"
        align="center"
        :reserve-selection="true"
      ></el-table-column>
      <el-table-column
        prop="host_sn"
        label="主机标识ID"
        min-width="180"
        align="center"
      >
        <template slot-scope="scope">
          <div @click="goCameraDetail(scope.row)">
            {{ scope.row.host_sn }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="device_sn"
        label="设备序列号"
        min-width="200"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.device_sn }}
        </template>
      </el-table-column>
      <el-table-column
        prop="alias"
        label="设备别名"
        min-width="180"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.alias }}
        </template>
      </el-table-column>
      <el-table-column
        prop="register_time"
        label="分配时间"
        min-width="130"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.register_time }}
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      right
      background
      layout="total,prev, pager, next, sizes,jumper"
      :page-sizes="pageSizesArr"
      :page-size="pagesize"
      :total="total"
      :current-page="currpage"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
  </div>
</template>

<script>
import { getData, postData } from "@/request/http";
export default {
  name: "",
  props: {},
  data() {
    return {
      placeholder: "", //搜索中placeholder
      select: "", //搜索中select
      input: "", //搜索中input
      currpage: 1, //当前页
      pagesize: globalPageSizes[0], //初始显示，一页几个
      pageSizesArr: globalPageSizes, //globalPageSizes在public--config中全局配置，每页显示个数数组
      total: 0, // 总数
      tableData: [], // 表格数据
      tableChecked: [], // 多选
      batchDelectId: [], //批量删除id
      checkAll: false, // 是否全选状态
    };
  },
  computed: {
    //刷新table
    submitData() {
      return this.$store.state.submitData;
    },
  },
  watch: {
    //刷新table
    submitData(newVal, oldVal) {
      if (newVal != oldVal) {
        //this.search();
        this.currpage = 1;
      }
    },
  },
  created() {},
  mounted() {
    this.search();

    if (this.select == 1) {
      this.placeholder = "请输入名称";
    } else if (this.select == 2) {
      this.placeholder = "请输入国标编码";
    } else if (this.select == 3) {
      this.placeholder = "请输入序列号";
    } else {
      this.placeholder = "请输入";
    }
  },
  methods: {
    // 搜索
    async fnSearch() {
      let { input, select } = this;
      this.currpage = 1;
      this.search();
    },
    //初始列表
    search() {
      let dataParams = {};
     // console.log(this.currpage, this.pagesize);
      if (this.select == 1) {
        dataParams = {
          page: this.currpage,
          page_num: this.pagesize,
          alias: this.input,
        };
      } else if (this.select == 2) {
        dataParams = {
          page: this.currpage,
          page_num: this.pagesize,
          dvcsn28181: this.input,
        };
      } else if (this.select == 3) {
        dataParams = {
          page: this.currpage,
          page_num: this.pagesize,
          dvcsn: this.input,
        };
      } else {
        dataParams = {
          page: this.currpage,
          page_num: this.pagesize,
        };
      }
      postData("/adminweb/host/device/list", dataParams)
        .then((res) => {
          if (res.code == 0) {
            if (!res.datas || !res.datas.devices) {
              return;
            }
            let devices = res.datas.devices;
            this.tableData = devices;
            this.total = res.datas.total_count;
          } else if (res.code == -56055) {
            return;
          } else {
            this.$message.error(res.code + "，" + res.msg);
          }
        })
        .catch((res) => {
          this.$message.error(res.code + "，" + res.msg);
        });
    },
    //全部
    FnAll() {
      this.currpage = 1;
      this.input = "";
      this.select = "";
      this.search();
    },

    // 获取row的key值
    getRowKeys(row) {
      return row.sn_gb28181;
    },
    //点击,第几页
    handleCurrentChange(cpage) {
      this.currpage = cpage;
      this.search();
    },
    //每页有几条
    handleSizeChange(psize) {
      this.currpage = 1;
      this.pagesize = psize;
      this.search();
    },
    //操作多选
    handleSelectionChange(val) {
      var that = this;
      this.batchDelectId = [];
      that.tableChecked = val;
    //  console.log(that.tableChecked);
      if (val.length > 0) {
        for (let i = 0; i < val.length; i++) {
          this.batchDelectId.push(val[i]["sn_gb28181"]);
        }
      }
    },
    //排序
    changeSort(val) {
     // console.log(val);
    },

    //点击列表的序列号，跳转
    goCameraDetail(val) {
      //console.log(val);
      var host_sn = val.host_sn;
      this.$router.push({
        path: "/hostList/HostDevice",
        query: { sn: host_sn },
      });
    },
    //table第一列小手样式
    changeCellStyle(row) {
      if (row.columnIndex === 1) {
        return "color:#3182bd;cursor: pointer";
      }
    },
  },
};
</script>
<style scoped>
.search-box {
  margin: 15px 0;
  width: 60%;
}
/* 更改table,表头背景 */
.wrap >>> .el-table--border th,
.el-table__fixed-right-patch {
  /* background: #c0dee2; */
  background: #f0f3f4;
}
.wrap {
  margin-top: 20px;
  background-color: #fff;
  padding: 15px;
  overflow: hidden;
}
.searchBox {
  margin-bottom: 20px;
}
.wrap >>> .el-pagination {
  float: right;
  margin-top: 30px;
}

.batch-btn-con {
  background: #fff;
  margin-top: 70px;
}
.wrap >>> .tips {
  margin-top: 10px;
  display: block;
  font-size: 15px;
}

/*title*/
.show-title {
  width: 100%;
  height: 40px;
  line-height: 40px;
  position: relative;
  background: #c0dee2;
  padding-left: 15px;
  font-size: 14px;
  margin: 6px 0 20px 0;
  border-radius: 12px 12px 0 0;
  font-weight: bold;
}

.show-title::before {
  content: "";
  width: 2px;
  height: 16px;
  background: #676a6d;
  position: absolute;
  top: 12px;
  left: 27px;
}

.show-title span {
  float: left;
  color: #676a6d;
  margin-left: 25px;
}
/* title显示名称id */
.wrap >>> .table-wrap {
  border: none;
  box-shadow: none;
}
.wrap >>> .el-divider__text.is-center {
  font-size: 17px;
}
.wrap >>> .el-divider__text {
  background: #c0dee2;
  padding: 15px;
  border-radius: 8px;
}
.title-list {
  background: #fff;
  padding-left: 20px;
  height: 80px;
}
.title-list .txt {
  height: 10px;
}
</style>
